﻿using System;
using System.Collections.Generic;
using System.Text;
using Torch.WL.Business.Interface;
using Torch.FrameWork.Utility;
using Torch.WL.Business.CleanChina;
using Torch.WL.Entity.CleanChina;

namespace Torch.WL.Business
{
    public class NewsProvider : BaseProvider<NewsProvider.RequestDataInfo>, IDataProvider
    {
        public NewsProvider(string _jsonInfo) : base(_jsonInfo)
        {

        }

        public IMessageInfo Do()
        {
            message.data = ProcessResponseData();
            return message;            
        }

        private List<ResponseDataInfo> ProcessResponseData()
        {
            if (postdata == null || postdata.data == null)
            {
                message.code = (int)MessageCodeType.WrongRequestPara;
                message.message = Utils.GetEnumDescription(MessageCodeType.WrongRequestPara);
                return null;
            }

            //use postdata.data to process responseData
            List<ResponseDataInfo> list = new List<ResponseDataInfo>();

            List<TbNewsEntity> listNews = TbNewsManager.Instance().GetNewsList(postdata.data.lessthan_newsid, postdata.data.pagesize);

            listNews.ForEach(delegate(TbNewsEntity entity) { list.Add(new ResponseDataInfo() {           
                news_id=entity.newsId,news_title=entity.title,news_date=entity.newsDate.ToString("yyyy-MM-dd")}); 
            });
            /*
            ResponseDataInfo responseData = new ResponseDataInfo();
            responseData.news_id = 100;
            responseData.news_title = "新闻标题1";
            responseData.news_date = "2013-03-15";
            list.Add(responseData);

            responseData = new ResponseDataInfo();
            responseData.news_id = 101;
            responseData.news_title = "新闻标题2";
            responseData.news_date = "2013-03-5"; 
            list.Add(responseData);

            responseData = new ResponseDataInfo();

            responseData.news_id = 102;
            responseData.news_title = "新闻标题3";
            responseData.news_date = "2013-02-15"; 
            list.Add(responseData);
            */
            return list;

         
        }

        public class RequestDataInfo 
        {
            public int lessthan_newsid { get; set; }
            public int pagesize { get; set; }
        }

        public class ResponseDataInfo
        {
            public int news_id { get; set; }
            public string news_title { get; set; }
            public string news_date { get; set; }     

        }


    }
}
